# main.py
from appium import webdriver
from utils.config import ConfigManager
from pages.login_page import LoginPage
from pages.ota_page import OTAPage
import time

class OTATestRunner:
    def __init__(self):
        self.driver = None
        self.config = ConfigManager()
        
    def initialize_driver(self):
        caps = self.config.capabilities
        self.driver = webdriver.Remote(
            caps['server_url'],
            caps['desired_caps']
        )
        self.driver.implicitly_wait(10)
        return self.driver
        
    def run(self):
        try:
            self.initialize_driver()
            LoginPage(self.driver).perform_login()
            OTAPage(self.driver).perform_ota_cycle()
        except Exception as e:
            OTAPage(self.driver).take_screenshot("main_error")
            raise
        finally:
            if self.driver:
                self.driver.quit()

if __name__ == "__main__":
    test_runner = OTATestRunner()
    test_runner.run()